package com.xc.erp.modules.erp.controller.depot;

import com.xc.erp.modules.erp.service.JshDepotItemService;
import com.xc.erp.modules.erp.domain.AjaxResult;
import com.xc.erp.modules.erp.domain.vo.FindDepotVo;
import com.xc.erp.modules.erp.domain.vo.FindDepotVo2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.LinkedList;
import java.util.List;

@RestController
@RequestMapping("/depotItem")
public class DepotItemController {
    @Autowired
    private JshDepotItemService jshDepotItemService;
 @GetMapping("/getDetailList")
    public AjaxResult getDetailList(Long headerId,@RequestParam(value = "isReadOnly",required = false) String isReadOnly){
     List<FindDepotVo> items = jshDepotItemService.findByDepotHeadId(headerId);
     if(items==null){
         return AjaxResult.error();
     }else{
         if("1".equals(isReadOnly)){
             Long operNumber=new Long(0);
             BigDecimal allPrice=new BigDecimal(0.0000);
             BigDecimal taxLastMoney=new BigDecimal(0.0000);;
             BigDecimal taxMoney=new BigDecimal(0.0000);;
             for (FindDepotVo findDepotVo:items) {
                 if(findDepotVo.getOperNumber()!=null)
                 operNumber+=findDepotVo.getOperNumber();
                 if(findDepotVo.getTaxLastMoney()!=null)
                 taxLastMoney=findDepotVo.getTaxLastMoney().add(taxLastMoney);
                 if(findDepotVo.getAllPrice()!=null)
                 allPrice=findDepotVo.getAllPrice().add(allPrice);
                 if(findDepotVo.getTaxMoney()!=null)
                 taxMoney=findDepotVo.getTaxMoney().add(taxMoney);
             }
             items.get(0).setOperNumber(operNumber);
             items.get(0).setAllPrice(allPrice);
             items.get(0).setTaxLastMoney(taxLastMoney);
             items.get(0).setTaxMoney(taxMoney);
         }
         return AjaxResult.success().put("rows",items).put("total",items.size());
     }
    }
}
